{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Prompt Formatting and Structure Tutorial\n",
    "\n",
    "## Overview\n",
    "\n",
    "This tutorial explores various prompt formats and structural elements in prompt engineering, demonstrating their impact on AI model responses. We'll use OpenAI's GPT model and the LangChain library to experiment with different prompt structures and analyze their effectiveness.\n",
    "\n",
    "## Motivation\n",
    "\n",
    "Understanding how to format and structure prompts is crucial for effective communication with AI models. Well-structured prompts can significantly improve the quality, relevance, and consistency of AI-generated responses. This tutorial aims to provide practical insights into crafting prompts that elicit desired outcomes across various use cases.\n",
    "\n",
    "## Key Components\n",
    "\n",
    "1. Different prompt formats (Q&A, dialogue, instructions)\n",
    "2. Structural elements (headings, bullet points, numbered lists)\n",
    "3. Comparison of prompt effectiveness\n",
    "4. Best practices for prompt formatting\n",
    "\n",
    "## Method Details\n",
    "\n",
    "We'll use the OpenAI API through LangChain to interact with the GPT model. The tutorial will demonstrate:\n",
    "\n",
    "1. Setting up the environment with necessary libraries\n",
    "2. Creating various prompt formats (Q&A, dialogue, instructions)\n",
    "3. Incorporating structural elements like headings and lists\n",
    "4. Comparing responses from different prompt structures\n",
    "\n",
    "Throughout the tutorial, we'll use a consistent theme (e.g., explaining a scientific concept) to showcase how different prompt formats and structures can yield varied results.\n",
    "\n",
    "## Conclusion\n",
    "\n",
    "By the end of this tutorial, you'll have a solid understanding of how prompt formatting and structure influence AI responses. You'll be equipped with practical techniques to craft more effective prompts, enhancing your ability to communicate with and leverage AI models for various applications."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Setup\n",
    "\n",
    "First, let's import the necessary libraries and set up our environment."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "from langchain_openai import ChatOpenAI\n",
    "from langchain.prompts import PromptTemplate\n",
    "\n",
    "# Load environment variables (make sure you have a .env file with your OpenAI API key)\n",
    "from dotenv import load_dotenv\n",
    "load_dotenv()\n",
    "\n",
    "os.environ[\"OPENAI_API_KEY\"] = os.getenv('OPENAI_API_KEY')\n",
    "\n",
    "# Initialize the language model\n",
    "llm = ChatOpenAI(model=\"gpt-4o-mini\")\n",
    "\n",
    "def get_response(prompt):\n",
    "    \"\"\"Helper function to get model response and print it.\"\"\"\n",
    "    response = llm.invoke(prompt).content\n",
    "    print(response)\n",
    "    print(\"-\" * 50)\n",
    "    return response"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exploring Different Prompt Formats\n",
    "\n",
    "Let's explore various prompt formats using the topic of photosynthesis as our consistent theme."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1. Question and Answer (Q&A) Format"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Photosynthesis is a biochemical process through which green plants, algae, and certain bacteria convert light energy, usually from the sun, into chemical energy stored in glucose (a type of sugar). This process primarily occurs in the chloroplasts of plant cells, using chlorophyll, the green pigment that captures light energy.\n",
      "\n",
      "The general equation for photosynthesis can be summarized as follows:\n",
      "\n",
      "\\[ 6 \\text{CO}_2 + 6 \\text{H}_2\\text{O} + \\text{light energy} \\rightarrow \\text{C}_6\\text{H}_{12}\\text{O}_6 + 6 \\text{O}_2 \\]\n",
      "\n",
      "In this reaction:\n",
      "- Carbon dioxide (CO₂) from the atmosphere and water (H₂O) from the soil are combined using light energy.\n",
      "- Glucose (C₆H₁₂O₆) is produced as a form of energy storage.\n",
      "- Oxygen (O₂) is released as a byproduct.\n",
      "\n",
      "Photosynthesis is essential for life on Earth as it provides the oxygen we breathe and is the foundation of the food chain, supporting most life forms by providing energy.\n",
      "--------------------------------------------------\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'Photosynthesis is a biochemical process through which green plants, algae, and certain bacteria convert light energy, usually from the sun, into chemical energy stored in glucose (a type of sugar). This process primarily occurs in the chloroplasts of plant cells, using chlorophyll, the green pigment that captures light energy.\\n\\nThe general equation for photosynthesis can be summarized as follows:\\n\\n\\\\[ 6 \\\\text{CO}_2 + 6 \\\\text{H}_2\\\\text{O} + \\\\text{light energy} \\\\rightarrow \\\\text{C}_6\\\\text{H}_{12}\\\\text{O}_6 + 6 \\\\text{O}_2 \\\\]\\n\\nIn this reaction:\\n- Carbon dioxide (CO₂) from the atmosphere and water (H₂O) from the soil are combined using light energy.\\n- Glucose (C₆H₁₂O₆) is produced as a form of energy storage.\\n- Oxygen (O₂) is released as a byproduct.\\n\\nPhotosynthesis is essential for life on Earth as it provides the oxygen we breathe and is the foundation of the food chain, supporting most life forms by providing energy.'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qa_prompt = \"\"\"Q: What is photosynthesis?\n",
    "A:\"\"\"\n",
    "\n",
    "get_response(qa_prompt)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2. Dialogue Format"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Teacher: Photosynthesis requires several key ingredients. A plant needs:\n",
      "\n",
      "1. **Sunlight**: This is the primary energy source for photosynthesis. Plants capture light energy using chlorophyll, the green pigment found in their leaves.\n",
      "\n",
      "2. **Carbon Dioxide**: Plants take in carbon dioxide from the air through small openings in their leaves called stomata. This gas is essential for the photosynthesis process.\n",
      "\n",
      "3. **Water**: Plants absorb water from the soil through their roots. Water is also a crucial component in the photosynthesis reaction.\n",
      "\n",
      "4. **Chlorophyll**: While not a raw material, chlorophyll is vital because it enables plants to convert sunlight into chemical energy.\n",
      "\n",
      "During photosynthesis, these ingredients combine to produce glucose (a type of sugar that serves as food for the plant) and oxygen, which is released as a byproduct. The overall equation for photosynthesis can be summarized as:\n",
      "\n",
      "\\[ \\text{6 CO}_2 + \\text{6 H}_2\\text{O} + \\text{light energy} \\rightarrow \\text{C}_6\\text{H}_{12}\\text{O}_6 + \\text{6 O}_2 \\]\n",
      "\n",
      "This process is crucial for life on Earth, as it provides food for plants and oxygen for other organisms.\n",
      "--------------------------------------------------\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'Teacher: Photosynthesis requires several key ingredients. A plant needs:\\n\\n1. **Sunlight**: This is the primary energy source for photosynthesis. Plants capture light energy using chlorophyll, the green pigment found in their leaves.\\n\\n2. **Carbon Dioxide**: Plants take in carbon dioxide from the air through small openings in their leaves called stomata. This gas is essential for the photosynthesis process.\\n\\n3. **Water**: Plants absorb water from the soil through their roots. Water is also a crucial component in the photosynthesis reaction.\\n\\n4. **Chlorophyll**: While not a raw material, chlorophyll is vital because it enables plants to convert sunlight into chemical energy.\\n\\nDuring photosynthesis, these ingredients combine to produce glucose (a type of sugar that serves as food for the plant) and oxygen, which is released as a byproduct. The overall equation for photosynthesis can be summarized as:\\n\\n\\\\[ \\\\text{6 CO}_2 + \\\\text{6 H}_2\\\\text{O} + \\\\text{light energy} \\\\rightarrow \\\\text{C}_6\\\\text{H}_{12}\\\\text{O}_6 + \\\\text{6 O}_2 \\\\]\\n\\nThis process is crucial for life on Earth, as it provides food for plants and oxygen for other organisms.'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dialogue_prompt = \"\"\"Student: Can you explain photosynthesis to me?\n",
    "Teacher: Certainly! Photosynthesis is...\n",
    "Student: What does a plant need for photosynthesis?\n",
    "Teacher:\"\"\"\n",
    "\n",
    "get_response(dialogue_prompt)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3. Instruction Format"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Photosynthesis is the biochemical process by which green plants, algae, and some bacteria convert light energy, usually from the sun, into chemical energy stored in glucose. This process primarily occurs in the chloroplasts of plant cells, where chlorophyll, the green pigment, captures light energy.\n",
      "\n",
      "The main components of photosynthesis are:\n",
      "\n",
      "1. **Light Energy**: Typically from sunlight, which provides the energy needed for the process.\n",
      "2. **Water (H2O)**: Absorbed by the roots from the soil and transported to the leaves.\n",
      "3. **Carbon Dioxide (CO2)**: Taken from the atmosphere through small openings in the leaves called stomata.\n",
      "\n",
      "The overall equation for photosynthesis can be summarized as:\n",
      "\\[ \\text{6 CO}_2 + \\text{6 H}_2\\text{O} + \\text{light energy} \\rightarrow \\text{C}_6\\text{H}_{12}\\text{O}_6 + \\text{6 O}_2 \\]\n",
      "This means that six molecules of carbon dioxide and six molecules of water, using light energy, are converted into one molecule of glucose and six molecules of oxygen.\n",
      "\n",
      "**Importance of Photosynthesis**:\n",
      "\n",
      "1. **Oxygen Production**: Photosynthesis releases oxygen as a byproduct, which is essential for the survival of most living organisms on Earth.\n",
      "2. **Food Source**: It forms the base of the food chain, as it enables plants to produce glucose, which serves as an energy source for themselves and for herbivores, and subsequently for carnivores.\n",
      "3. **Carbon Dioxide Reduction**: Photosynthesis helps regulate atmospheric CO2 levels, playing a critical role in mitigating climate change.\n",
      "4. **Energy Source**: It is the primary means by which solar energy is converted into chemical energy, which is then utilized by various organisms.\n",
      "\n",
      "Overall, photosynthesis is fundamental to life on Earth, supporting ecosystems and contributing to the planet's climate stability.\n",
      "--------------------------------------------------\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "\"Photosynthesis is the biochemical process by which green plants, algae, and some bacteria convert light energy, usually from the sun, into chemical energy stored in glucose. This process primarily occurs in the chloroplasts of plant cells, where chlorophyll, the green pigment, captures light energy.\\n\\nThe main components of photosynthesis are:\\n\\n1. **Light Energy**: Typically from sunlight, which provides the energy needed for the process.\\n2. **Water (H2O)**: Absorbed by the roots from the soil and transported to the leaves.\\n3. **Carbon Dioxide (CO2)**: Taken from the atmosphere through small openings in the leaves called stomata.\\n\\nThe overall equation for photosynthesis can be summarized as:\\n\\\\[ \\\\text{6 CO}_2 + \\\\text{6 H}_2\\\\text{O} + \\\\text{light energy} \\\\rightarrow \\\\text{C}_6\\\\text{H}_{12}\\\\text{O}_6 + \\\\text{6 O}_2 \\\\]\\nThis means that six molecules of carbon dioxide and six molecules of water, using light energy, are converted into one molecule of glucose and six molecules of oxygen.\\n\\n**Importance of Photosynthesis**:\\n\\n1. **Oxygen Production**: Photosynthesis releases oxygen as a byproduct, which is essential for the survival of most living organisms on Earth.\\n2. **Food Source**: It forms the base of the food chain, as it enables plants to produce glucose, which serves as an energy source for themselves and for herbivores, and subsequently for carnivores.\\n3. **Carbon Dioxide Reduction**: Photosynthesis helps regulate atmospheric CO2 levels, playing a critical role in mitigating climate change.\\n4. **Energy Source**: It is the primary means by which solar energy is converted into chemical energy, which is then utilized by various organisms.\\n\\nOverall, photosynthesis is fundamental to life on Earth, supporting ecosystems and contributing to the planet's climate stability.\""
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "instruction_prompt = \"\"\"Provide a brief explanation of photosynthesis, including its main components and importance.\"\"\"\n",
    "\n",
    "get_response(instruction_prompt)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Impact of Structural Elements\n",
    "\n",
    "Now, let's examine how structural elements like headings and lists affect the AI's response."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1. Using Headings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "# Definition\n",
      "Photosynthesis is the biochemical process by which green plants, algae, and certain bacteria convert light energy, usually from the sun, into chemical energy stored in glucose. This process involves the transformation of carbon dioxide and water into glucose and oxygen, using chlorophyll found in chloroplasts.\n",
      "\n",
      "# Process\n",
      "Photosynthesis occurs primarily in two stages: the light-dependent reactions and the light-independent reactions (Calvin Cycle).\n",
      "\n",
      "1. **Light-dependent Reactions**: These reactions take place in the thylakoid membranes of chloroplasts. When chlorophyll absorbs sunlight, it energizes electrons, which then travel through a series of proteins known as the electron transport chain. This process splits water molecules (photolysis), releasing oxygen as a byproduct and generating ATP (adenosine triphosphate) and NADPH (nicotinamide adenine dinucleotide phosphate), which are energy carriers.\n",
      "\n",
      "2. **Light-independent Reactions (Calvin Cycle)**: These reactions occur in the stroma of the chloroplasts. Using the ATP and NADPH produced in the light-dependent reactions, carbon dioxide is fixed through a series of enzymatic reactions to produce glucose. The Calvin Cycle involves three main phases: carbon fixation, reduction, and regeneration of ribulose bisphosphate (RuBP).\n",
      "\n",
      "# Importance\n",
      "Photosynthesis is crucial for life on Earth for several reasons:\n",
      "\n",
      "1. **Oxygen Production**: It produces oxygen as a byproduct, which is essential for the respiration of most living organisms.\n",
      "\n",
      "2. **Energy Source**: Photosynthesis is the foundation of the food chain. Plants convert solar energy into chemical energy in the form of glucose, which serves as food for herbivores, and subsequently for carnivores.\n",
      "\n",
      "3. **Carbon Dioxide Regulation**: It helps regulate atmospheric carbon dioxide levels, playing a critical role in mitigating climate change by absorbing CO2 during the process.\n",
      "\n",
      "4. **Ecosystem Support**: Photosynthesis supports ecosystems by providing energy and nutrients that sustain various biological processes and interactions, thus maintaining biodiversity.\n",
      "--------------------------------------------------\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'# Definition\\nPhotosynthesis is the biochemical process by which green plants, algae, and certain bacteria convert light energy, usually from the sun, into chemical energy stored in glucose. This process involves the transformation of carbon dioxide and water into glucose and oxygen, using chlorophyll found in chloroplasts.\\n\\n# Process\\nPhotosynthesis occurs primarily in two stages: the light-dependent reactions and the light-independent reactions (Calvin Cycle).\\n\\n1. **Light-dependent Reactions**: These reactions take place in the thylakoid membranes of chloroplasts. When chlorophyll absorbs sunlight, it energizes electrons, which then travel through a series of proteins known as the electron transport chain. This process splits water molecules (photolysis), releasing oxygen as a byproduct and generating ATP (adenosine triphosphate) and NADPH (nicotinamide adenine dinucleotide phosphate), which are energy carriers.\\n\\n2. **Light-independent Reactions (Calvin Cycle)**: These reactions occur in the stroma of the chloroplasts. Using the ATP and NADPH produced in the light-dependent reactions, carbon dioxide is fixed through a series of enzymatic reactions to produce glucose. The Calvin Cycle involves three main phases: carbon fixation, reduction, and regeneration of ribulose bisphosphate (RuBP).\\n\\n# Importance\\nPhotosynthesis is crucial for life on Earth for several reasons:\\n\\n1. **Oxygen Production**: It produces oxygen as a byproduct, which is essential for the respiration of most living organisms.\\n\\n2. **Energy Source**: Photosynthesis is the foundation of the food chain. Plants convert solar energy into chemical energy in the form of glucose, which serves as food for herbivores, and subsequently for carnivores.\\n\\n3. **Carbon Dioxide Regulation**: It helps regulate atmospheric carbon dioxide levels, playing a critical role in mitigating climate change by absorbing CO2 during the process.\\n\\n4. **Ecosystem Support**: Photosynthesis supports ecosystems by providing energy and nutrients that sustain various biological processes and interactions, thus maintaining biodiversity.'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "headings_prompt = \"\"\"Explain photosynthesis using the following structure:\n",
    "\n",
    "# Definition\n",
    "\n",
    "# Process\n",
    "\n",
    "# Importance\n",
    "\"\"\"\n",
    "\n",
    "get_response(headings_prompt)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2. Using Bullet Points"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The key components needed for photosynthesis are:\n",
      "\n",
      "• **Chlorophyll** (the green pigment in plants that captures light energy)\n",
      "• **Carbon Dioxide** (absorbed from the atmosphere through stomata)\n",
      "• **Water** (taken up by the roots from the soil)\n",
      "\n",
      "Additionally, light energy (usually from the sun) is also essential for the process.\n",
      "--------------------------------------------------\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'The key components needed for photosynthesis are:\\n\\n• **Chlorophyll** (the green pigment in plants that captures light energy)\\n• **Carbon Dioxide** (absorbed from the atmosphere through stomata)\\n• **Water** (taken up by the roots from the soil)\\n\\nAdditionally, light energy (usually from the sun) is also essential for the process.'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bullet_points_prompt = \"\"\"List the key components needed for photosynthesis:\n",
    "\n",
    "• \n",
    "• \n",
    "• \n",
    "\"\"\"\n",
    "\n",
    "get_response(bullet_points_prompt)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3. Using Numbered Lists"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Photosynthesis occurs in two main stages: the light-dependent reactions and the light-independent reactions (Calvin cycle). Here are the steps in order:\n",
      "\n",
      "1. **Light Absorption**: Chlorophyll and other pigments in the chloroplasts absorb sunlight, primarily in the blue and red wavelengths.\n",
      "\n",
      "2. **Water Splitting (Photolysis)**: The absorbed light energy is used to split water molecules (H₂O) into oxygen (O₂), protons (H⁺), and electrons (e⁻). This process occurs in the thylakoid membranes.\n",
      "\n",
      "3. **Electron Transport Chain**: The energized electrons travel through a series of proteins in the thylakoid membrane known as the electron transport chain. As the electrons move, their energy is used to pump protons into the thylakoid lumen, creating a proton gradient.\n",
      "\n",
      "4. **ATP and NADPH Formation**: The proton gradient drives ATP synthesis through ATP synthase, and the electrons ultimately reduce NADP⁺ to form NADPH. Both ATP and NADPH are then used in the Calvin cycle.\n",
      "\n",
      "5. **Calvin Cycle (Light-Independent Reactions)**: In the stroma of the chloroplasts, ATP and NADPH produced in the light-dependent reactions are used to convert carbon dioxide (CO₂) from the atmosphere into glucose (C₆H₁₂O₆) through a series of enzymatic reactions.\n",
      "\n",
      "These steps outline the process of photosynthesis, which converts light energy into chemical energy stored in glucose, while releasing oxygen as a byproduct.\n",
      "--------------------------------------------------\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'Photosynthesis occurs in two main stages: the light-dependent reactions and the light-independent reactions (Calvin cycle). Here are the steps in order:\\n\\n1. **Light Absorption**: Chlorophyll and other pigments in the chloroplasts absorb sunlight, primarily in the blue and red wavelengths.\\n\\n2. **Water Splitting (Photolysis)**: The absorbed light energy is used to split water molecules (H₂O) into oxygen (O₂), protons (H⁺), and electrons (e⁻). This process occurs in the thylakoid membranes.\\n\\n3. **Electron Transport Chain**: The energized electrons travel through a series of proteins in the thylakoid membrane known as the electron transport chain. As the electrons move, their energy is used to pump protons into the thylakoid lumen, creating a proton gradient.\\n\\n4. **ATP and NADPH Formation**: The proton gradient drives ATP synthesis through ATP synthase, and the electrons ultimately reduce NADP⁺ to form NADPH. Both ATP and NADPH are then used in the Calvin cycle.\\n\\n5. **Calvin Cycle (Light-Independent Reactions)**: In the stroma of the chloroplasts, ATP and NADPH produced in the light-dependent reactions are used to convert carbon dioxide (CO₂) from the atmosphere into glucose (C₆H₁₂O₆) through a series of enzymatic reactions.\\n\\nThese steps outline the process of photosynthesis, which converts light energy into chemical energy stored in glucose, while releasing oxygen as a byproduct.'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "numbered_list_prompt = \"\"\"Describe the steps of photosynthesis in order:\n",
    "\n",
    "1.\n",
    "2.\n",
    "3.\n",
    "4.\n",
    "\"\"\"\n",
    "\n",
    "get_response(numbered_list_prompt)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Comparing Prompt Effectiveness\n",
    "\n",
    "Let's compare the effectiveness of different prompt structures for a specific task."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Prompt 1:\n",
      "Photosynthesis is a crucial biological process that significantly impacts life on Earth for several reasons:\n",
      "\n",
      "1. **Oxygen Production**: Photosynthesis is the primary source of atmospheric oxygen. During the process, plants, algae, and some bacteria convert carbon dioxide and water into glucose and oxygen using sunlight. This oxygen is essential for the survival of most living organisms that rely on aerobic respiration to generate energy.\n",
      "\n",
      "2. **Foundation of Food Chains**: Photosynthesis forms the base of the food chain. Producers, such as plants and phytoplankton, harness solar energy to create organic matter. Herbivores consume these producers, and in turn, carnivores feed on herbivores. This flow of energy and nutrients is vital for the survival of all ecosystems.\n",
      "\n",
      "3. **Carbon Dioxide Regulation**: Photosynthesis plays a critical role in regulating atmospheric carbon dioxide levels. By absorbing CO2, photosynthetic organisms help mitigate the greenhouse effect and climate change. This regulation is essential for maintaining the planet's climate and supporting diverse life forms.\n",
      "\n",
      "4. **Energy Source**: Photosynthesis is the primary means of converting solar energy into chemical energy stored in glucose. This energy is then available to be consumed by other organisms, making it a fundamental energy source for almost all life on Earth.\n",
      "\n",
      "5. **Biodiversity Support**: By producing organic matter and oxygen, photosynthesis supports a wide variety of ecosystems and promotes biodiversity. Healthy ecosystems contribute to the stability and resilience of the environment, providing habitats for countless species.\n",
      "\n",
      "6. **Soil Formation and Health**: Photosynthetic organisms contribute to soil health by creating organic matter through decaying plant material. This organic matter enriches the soil, improving its structure, fertility, and ability to retain water, which is vital for agriculture and natural vegetation.\n",
      "\n",
      "In summary, photosynthesis is essential for life on Earth as it provides oxygen, forms the basis of food chains, helps regulate carbon dioxide levels, serves as a primary energy source, supports biodiversity, and contributes to soil health. Its significance extends beyond individual organisms to the overall health of the planet's ecosystems.\n",
      "--------------------------------------------------\n",
      "Prompt 2:\n",
      "Photosynthesis is a vital process that supports life on Earth in several key ways. Here’s a structured explanation of its importance:\n",
      "\n",
      "### 1. Oxygen Production\n",
      "Photosynthesis is primarily responsible for the production of oxygen in the atmosphere. During this process, plants, algae, and certain bacteria convert carbon dioxide and water into glucose and oxygen, using sunlight as an energy source. The overall equation for photosynthesis can be summarized as:\n",
      "\n",
      "\\[ \\text{6 CO}_2 + \\text{6 H}_2\\text{O} + \\text{light energy} \\rightarrow \\text{C}_6\\text{H}_{12}\\text{O}_6 + \\text{6 O}_2 \\]\n",
      "\n",
      "The oxygen released is crucial for the survival of aerobic organisms, including humans. It is utilized in cellular respiration, a process that generates energy for living beings. Without photosynthesis, the oxygen levels in the atmosphere would diminish, leading to a collapse of most life forms that depend on it for respiration.\n",
      "\n",
      "### 2. Food Chain Support\n",
      "Photosynthesis forms the foundation of the food chain. The glucose produced during photosynthesis serves as an energy source for autotrophs (organisms that produce their own food, such as plants). These autotrophs are then consumed by herbivores (primary consumers), which are in turn eaten by carnivores (secondary and tertiary consumers). This interconnected network of energy transfer is vital for maintaining ecological balance. As a result, the health and productivity of ecosystems are largely dependent on the efficiency of photosynthesis, making it essential for sustaining life on Earth.\n",
      "\n",
      "### 3. Carbon Dioxide Absorption\n",
      "Photosynthesis plays a crucial role in regulating atmospheric carbon dioxide levels. Plants absorb carbon dioxide from the atmosphere during the process of photosynthesis, helping to mitigate the greenhouse effect and combat climate change. By removing CO2, which is a significant greenhouse gas, photosynthesis contributes to climate regulation and maintains the balance of carbon in the ecosystem. This absorption is particularly important in the context of rising CO2 levels due to human activities, as it helps to offset some of the impacts of global warming.\n",
      "\n",
      "In summary, photosynthesis is fundamental to life on Earth through its production of oxygen, support of food chains, and absorption of carbon dioxide. It not only sustains individual organisms but also plays a critical role in maintaining the planet's ecological and atmospheric balance.\n",
      "--------------------------------------------------\n",
      "Prompt 3:\n",
      "A: Photosynthesis is crucial for life on Earth because:\n",
      "\n",
      "1. **Oxygen Production**: Photosynthesis generates oxygen as a byproduct, which is essential for the survival of most living organisms. It provides the oxygen that we breathe, supporting aerobic respiration.\n",
      "\n",
      "2. **Food Source**: It serves as the primary source of energy for nearly all ecosystems. Plants, algae, and some bacteria convert sunlight into chemical energy in the form of glucose, which is then used as food by herbivores and, subsequently, by carnivores.\n",
      "\n",
      "3. **Carbon Dioxide Absorption**: Photosynthesis helps regulate atmospheric carbon dioxide levels. By absorbing CO2 from the atmosphere, it plays a key role in mitigating climate change and maintaining the planet's carbon balance.\n",
      "--------------------------------------------------\n"
     ]
    }
   ],
   "source": [
    "comparison_prompts = [\n",
    "    \"Explain the importance of photosynthesis for life on Earth.\",\n",
    "    \"\"\"Explain the importance of photosynthesis for life on Earth. Structure your answer as follows:\n",
    "    1. Oxygen production\n",
    "    2. Food chain support\n",
    "    3. Carbon dioxide absorption\"\"\",\n",
    "    \"\"\"Q: Why is photosynthesis important for life on Earth?\n",
    "    A: Photosynthesis is crucial for life on Earth because:\n",
    "    1.\n",
    "    2.\n",
    "    3.\"\"\"\n",
    "]\n",
    "\n",
    "for i, prompt in enumerate(comparison_prompts, 1):\n",
    "    print(f\"Prompt {i}:\")\n",
    "    get_response(prompt)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
